<?php

function createAddPersonFields($person_info = null) {
?>
<form method='post'>
	<input type='hidden' name='action' value='search_person'/>
	<h2 class='admin'>Lookup a Person</h2>
	<table class='adminForm'>
		<tr><td class='h r'>First Name:</td><td><input type='text' name='fname'/></td>
		<td class='h r'>Last Name:</td><td><input type='text' name='lname'/></td></tr>
		<tr><td colspan=4 style='text-align: center'>
			<? if($person_info['error']): ?> <b><?=$person_info['error']?></b> <? endif; ?><br/><br/>
			<input class='button' type='submit' value='Lookup Person' />
		</td></tr>
	</table>
</form>
<?
if ($person_info['person_id']) {
	$person_id = $person_info['person_id'];
	$name = htmlspecialchars($person_info['name']);
	list($lname, $fname) = split(', ', $person_info['name'], 2);
	list($byear, $bmonth, $bday) = split('-', $person_info['birth_date'], 3);
	list($dyear, $dmonth, $dday) = split('-', $person_info['death_date'], 3);
	$photo_url = $person_info['photo_url'];
}
?>
<form method='post' name='personForm'>
	<input type='hidden' name='action' value='<? echo $person_info['person_id'] ? 'update' : 'add'; ?>_person'/>
	<? if ($person_info['person_id']) echo "<input type='hidden' name='person_id' value='$person_id'/>"; ?>
	<h2 class='admin'>
		<? if(!$person_info['person_id'])
			echo "Add a Person";
		else echo "Update <a href='".getBasePath()."/person/$person_id'>$person_info[name]</a>";
		?>
	</h2>
	<table class='adminForm'>
		<tr><td class='h r'>First Name:</td><td><input type='text' name='fname' value='<?=$fname?>'/></td>
		<td class='h r'>Last Name:</td><td><input type='text' name='lname' value='<?=$lname?>'/></td></tr>
		<tr><td class='h'>Birth Date:</td><td>
			<select class='dropdown' name='birth_month'>
				<option value=''>Month&nbsp;&nbsp;</option>
				<? for ($i=1; $i <= 12; $i++)
					if (1*$bmonth == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
				?>
			</select>
			<select class='dropdown' name='birth_day'>
				<option value=''>Day&nbsp;&nbsp;</option>
				<? for ($i=1; $i <= 31; $i++)
					if (1*$bday == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
				?>
			</select>
			<select class='dropdown' name='birth_year'>
				<option value=''>Year&nbsp;&nbsp;</option>
				<? for ($i=2008; $i >= 1850; $i--)
					if (1*$byear == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
v				?>
			</select></td>

		<td class='h'>Death Date:</td><td>
			<select class='dropdown' name='death_month'>
				<option value=''>Month&nbsp;&nbsp;</option>
				<? for ($i=1; $i <= 12; $i++)
					if (1*$dmonth == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
				?>
			</select>
			<select class='dropdown' name='death_day'>
				<option value=''>Day&nbsp;&nbsp;</option>
				<? for ($i=1; $i <= 31; $i++)
					if (1*$dday == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
				?>
			</select>
			<select class='dropdown' name='death_year'>
				<option value=''>Year&nbsp;&nbsp;</option>
				<? for ($i=2008; $i >= 1850; $i--)
					if (1*$dyear == $i) echo "<option value='$i' selected='selected'>$i</option>";
					else echo "<option value='$i'>$i</option>";
				?>
			</select></td></tr>


		<tr><td class='h'>Photo URL:</td><td>
			<input type='text' name='photo_url' value='<?=$photo_url?>'/>
		</td></tr>
		<tr><td colspan=4 style='text-align: center'>
			<? if ($person_info['msg']): ?><b><?=$person_info['msg']?></b><? endif; ?><br/><br/>
			<? if ($person_info['person_id']): ?>
			<input class='button' type='submit' value='Update <?=$person_info['name']?>'/>

			<input style ='margin-left: 100px; color: #c00' type='button' value='Delete <?=$person_info['name']?>'
				onclick="if (confirm('Are you sure you want to delete this person?\n\nWARNING: ALL DATA FOR THIS PERSON WILL BE LOST!')) {document.personForm.getElementsByTagName('input')[0].value='delete_person';document.personForm.submit()}"/>
			<? else: ?>
			<input class='button' type='submit' value='Add Person'/>
			<? endif; ?>
		</td></tr>
	</table>
</form>
<?
}

function createAddProjectFields($project_info = null) {

if ($project_info['project_id']) {
	$project_id = $project_info['project_id'];
	if ($project_info['title'][0] == '"')
		$title = htmlspecialchars(substr($project_info['title'], 1, strlen($project_info['title'])-2));
	else
		$title = htmlspecialchars($project_info['title']);
	$year = $project_info['year'];
	$episode = htmlspecialchars($project_info['episode']);
	if (empty($project_info['other']))
		$medium =  $project_info['title'][0] == '"' ? 'television' : 'movie';
	else	$medium = $project_info['other'];
	$votes = $project_info['votes'];
	$rating = $project_info['rating'];
	list($year, $month, $day) = split('-', $project_info['usa_release_date'], 3);
	$genres = $project_info['genres'];
} else {
	$genres = array();
}

?>
<form method='post'>
	<input type='hidden' name='action' value='search_project'/>
	<h2 class='admin'>Lookup a Project</h2>
	<table class='adminForm'>
		<tr>
			<td class='h r'>Medium:</td>
			<td><select name='medium'>
				<option value='movie'>Movie</option>
				<option value='TV'>Movie: Made for TV </option>
				<option value='V'>Movie: Made for Video</option>
				<option value='television'>Television</option>
				<option value='mini'>Television Mini-series</option>
				<option value='VG'>Video Game</option>
			</select></td>
			<td class='h r'>Release Year:</td>
			<td>
				<select name='year'>
					<option value=''>Year&nbsp;&nbsp;</option>
					<? for ($i = 2010; $i >= 1850; $i--): ?>
					<option value='<?=$i?>'><?=$i?></option>
					<? endfor; ?>
				</select>
			</td>
			<td class='h r'>Title:</td>
			<td><input name='title'/></td>
			<td class='h'>Episode:</td>
			<td><input name='episode'/></td>
		</tr>
		<tr><td colspan=8 style='text-align:center'>
			<? if ($project_info['error']) echo "<b>$project_info[error]</b>"; ?>
			<br/><br/><input type='submit' value='Lookup Project'/></td></tr>
	</table>
</form>
<form method='post' name='projectForm'>
	<input type='hidden' name='action' value='<?=($project_info['project_id']?'update':'add')?>_project'/>
	<? if ($project_info['project_id']): ?>
	<input type='hidden' name='project_id' value='<?=$project_id?>'/>
	<? endif; ?>
	<h2 class='admin'><?=($project_info['project_id']?"Update $project_info[title]":"Add a Project")?></h2>
	<table class='adminForm'>
		<tr>
			<td class='h r'>Medium:</td>
			<td><select name='medium'>
				<? $mediums = array('movie' => 'Movie', 'TV' => 'Movie: Made for TV',
					'V' => 'Movie: Made for Video', 'television' => 'Television',
					'mini' => 'Television Mini-series', 'VG' => 'Video Game');
				foreach ($mediums as $i => $j)
					if ($i == $medium)	echo "<option value='$i' selected='selected'>$j</option>";
					else echo "<option value='$i'>$j</option>";
				?>
			</select></td>
			<td class='h r'>Release Date:</td>
			<td>
				<select name='year'>
					<option value=''>Year&nbsp;&nbsp;</option>
					<? for ($i = 2010; $i >= 1850; $i--): ?>
					<option value='<?=$i?>'<? if($i == 1*$year) echo " selected='selected'";?>><?=$i?></option>
					<? endfor; ?>
				</select>
				Optional:
				<select name='month'>
					<option value=''>Month&nbsp;&nbsp;</option>
					<? for ($i = 1; $i < 13; $i++): ?>
					<option value='<?=$i?>'<? if($i == 1*$month) echo " selected='selected'";?>><?=$i?></option>
					<? endfor; ?>
				</select>
				<select name='day'>
					<option value=''>Day&nbsp;&nbsp;</option>
					<? for ($i = 1; $i < 32; $i++): ?>
					<option value='<?=$i?>'<? if($i == 1*$day) echo " selected='selected'";?>><?=$i?></option>
					<? endfor; ?>
				</select>

			</td>
		</tr>
		<tr>
			<td class='h r'>Title:</td>
			<td><input name='title' value="<?=$title?>"/></td>
			<td class='h'>Episode:</td>
			<td><input name='episode' value="<?=$episode?>"/></td>
		</tr>
		<tr>
			<td class='h'>Votes:</td>
			<td><input name='votes' size=6 value='<?=$votes?>'/></td>
			<td class='h'>Rating:</td>
			<td><input name='rating' size=3 value='<?=$rating?>'/></td>
		</tr>
	</table>
	<table class='adminForm'>
		<tr><td colspan=7 style='text-align:center'>
			<br/><b><u>Genres</u></b></td></tr>
		<? $gs = array('Action', 'Adult', 'Adventure', 'Animation', 
			'Biography', 'Comedy', 'Crime', 'Documentary', 'Drama',
			'Family', 'Fantasy', 'Film-Noir', 'Game-Show', 'History', 
			'Horror', 'Music', 'Musical', 'Mystery', 'News', 'Reality-TV', 
			'Romance', 'Sci-Fi', 'Short', 'Sport', 'Talk-Show', 'Thriller', 
			'War', 'Western');
		foreach ($gs as $i => $genre): ?>
			<? if ($i % 7 == 0) echo "<tr class='genres'>"; ?>
			<td><input type='checkbox' name='genres[]' value='<?=$genre?>'<?
				foreach ($genres as $g)
					if ($g == $genre) echo " checked";
			?>> <?=$genre?></input></td>
			<? if ($i % 7 == 6) echo "</tr>"; ?>
		<? endforeach; ?>
		<tr>
			<td colspan=7 style='text-align: center'>
			<? if ($project_info['msg']) echo "<b>$project_info[msg]</b>"; ?>
			</br><br/>
			<? if (!$project_info['project_id']): ?>
			<input type='submit' value='Add Project'/>
			<? else: ?>
			<input type='submit' value="Update <?=$title?>"/>

			<input style ='margin-left: 100px; color: #c00' type='button' value="Delete <?=$title?>"
				onclick="if (confirm('Are you sure you want to delete this project?\n\nWARNING: ALL DATA FOR THIS PROJECT WILL BE LOST!')) {document.projectForm.getElementsByTagName('input')[0].value='delete_project';document.projectForm.submit()}"/>
			<? endif; ?>
			</td>
		</tr>
	</table>
</form>
<?
}

function createAddJobFields($job_info = null) {
?>
<form method='post' name='jobForm'>
	<input type='hidden' name='action' value='add_job'/>
	<h2 class='admin'>Jobs</h2>
	<h3 class='admin'>Person Info</h3>
	<table class='adminForm'>
		<tr><td class='h r'>First Name:</td><td><input type='text' name='fname'/></td>
		<td class='h r'>Last Name:</td><td><input type='text' name='lname'/></td></tr>
	</table>
	<h3 class='admin'>Project Info</h3>
	<table class='adminForm'>
		<tr>
			<td class='h r'>Medium:</td>
			<td><select name='medium'>
				<? $mediums = array('movie' => 'Movie', 'TV' => 'Movie: Made for TV',
					'V' => 'Movie: Made for Video', 'television' => 'Television',
					'mini' => 'Television Mini-series', 'VG' => 'Video Game');
				foreach ($mediums as $i => $j)
					echo "<option value='$i'>$j</option>";
				?>
			</select></td>
			<td class='h r'>Release Year:</td>
			<td>
				<select name='year'>
					<option value=''>Year&nbsp;&nbsp;</option>
					<? for ($i = 2010; $i >= 1850; $i--): ?>
					<option value='<?=$i?>'><?=$i?></option>
					<? endfor; ?>
				</select>
			</td>
			<td class='h r'>Title:</td>
			<td><input name='title'/></td>
			<td class='h'>Episode:</td>
			<td><input name='episode'/></td>
		</tr>
	</table>
	<h3 class='admin'>Job Info</h3>
	<table class='adminForm'>
		<tr><td class='h r'>Job Title:</td>
			<td><select name='job_title'>
				<? $job_titles = array('Actress', 'Actor', 'Director', 'Producer', 'Writer');
				foreach ($job_titles as $j)
					echo "<option value='$j'>$j</option>";
				?>
			</select>
		</td>
		<td class='h'>Billing Position:</td><td><input name='billing_position' size=4/></td></tr>
		<tr><td colspan=4 style='text-align:center'>
			<? if ($job_info['msg']) echo "<b>$job_info[msg]</b>"; ?>
			<br/><br/>
			<input type='submit' value='Add Job'/>
			<input style ='margin-left: 100px; color: #c00' type='button' value="Delete Job"
				onclick="if (confirm('Are you sure you want to delete this job?\n\nWARNING: ALL DATA FOR THIS JOB WILL BE LOST!')) {document.jobForm.getElementsByTagName('input')[0].value='delete_job';document.jobForm.submit()}"/>
		</td></tr>
	</table>
</form>

<?
}
?>
